
cc.Class({
    
    extends: cc.Component,

    properties: {
        progressBar :{     //进度条节点
            default:null,
            type:cc.Node,  
        },
        progressData:{  //进度百分比
            default:null,
            type:cc.Label
        },
    },

    onLoad () {
        
        this.node.on(cc.Node.EventType.TOUCH_START, this.secondButtonClick, this);
    },


    getParams() {
        if (cc.vv.userMgr.depth == 0) {
            let diamondMap = new Map()
            diamondMap.set("D",0) 
            diamondMap.set("E",1) 
            diamondMap.set("F",2) 
            diamondMap.set("G",3) 
            var diamondDepthAdd = diamondMap.get(cc.vv.currentDiamond.name[0])
        }else {
            let diamondMap = new Map()
            diamondMap.set("A",0) 
            diamondMap.set("B",1) 
            diamondMap.set("C",2) 
            diamondMap.set("D",3) 
            diamondMap.set("E",4) 
            diamondMap.set("F",5) 
            diamondMap.set("G",6) 
            var diamondDepthAdd = diamondMap.get(cc.vv.currentDiamond.name[0])
            return params = {
                user_id : cc.vv.userMgr.userid,
                depth : cc.vv.userMgr.depth + diamondDepthAdd,
                position : cc.vv.currentDiamond.name[1],
            }
        }
    },
    secondButtonClick(event) {
        cc.log("生成事件触发")
        var grandInfoBackground = cc.find('Canvas/grandInfo');
        var topshow = cc.find('Canvas/topshow')
        if(topshow.childrenCount > 0) {     //点击到其他节点的时候清除另一个节点的按钮
            for(var i = topshow.childrenCount - 1; i >= 0; i--) {
                topshow.children[i].destroy();
            }
        }
        if (grandInfoBackground) {
            grandInfoBackground.active = true;
        } else {
            console.error("grandInfoBackground node not found");
        }
        
        
        
        var params = this.getParams()
        
        cc.vv.http.sendRequest("getOneDiamondInfo",params,function(data) {
            
            if (data.code == 400) {
                cc.log("errmsg",data.msg)
            }
            var stateNode = cc.find('Canvas/grandInfo/background/state');
            var stateLabel = stateNode.getComponent(cc.Label);
            stateLabel.horizontalAlign = cc.Label.HorizontalAlign.LEFT;
            if (stateLabel) {
                var diamondName = "";
                switch(data.data.diamond.diamond_state) {
                    case 0:
                        diamondName = "土壤";
                        break;
                    case 1:
                        diamondName = "铁块";
                        break;
                    case 2:
                        diamondName = "石料";
                        break;
                    case 3:
                        diamondName = "黄金";
                        break;
                    case 4:
                        diamondName = "钻石";
                        break;
                    case 5:
                        diamondName = "空";
                        break;
                }
                
                stateLabel.string = "方块类型：" + diamondName;
            }
            
            var numberNode = cc.find('Canvas/grandInfo/background/number');
            var numberLabel = numberNode.getComponent(cc.Label);
            numberLabel.horizontalAlign = cc.Label.HorizontalAlign.LEFT;
            if (numberLabel) {
                numberLabel.string = "资源含量：" + data.data.diamond.number.toString(); 
            }
            
            var durabilityNode = cc.find('Canvas/grandInfo/background/durability');
            var durabilityLabel = durabilityNode.getComponent(cc.Label);
            durabilityLabel.horizontalAlign = cc.Label.HorizontalAlign.LEFT;
            if (durabilityLabel) {
                durabilityLabel.string = "方块耐久：" + data.data.diamond.durability.toString(); 
            }
            
        },cc.vv.url.diamondServer)
    },

    
    start () {
        
    },

    // update (dt) {},
});
